﻿//********************************************************************************//
//创建日期：<创建日期，2016-05-29>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：来涵用户基本信息_并户
//********************************************************************************//

using System;
using System.Data;
using System.Web.UI;
using BLL;
using DevExpress.Web;
using Entity;
using Web.Class;
using Web.Controls.LAIHAN;

namespace Web.Controls
{
    public partial class UCLHUserInfo_BH : UserControl, IUCLHOperate
    {
        #region 属性

        /// <summary>
        ///     来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        /// <summary>
        ///     来函流程步骤
        /// </summary>
        public eLaiHanLCBH LaiHanLC { get; set; }

        /// <summary>
        ///     用户号
        /// </summary>
        public string YONGHUH
        {
            get { return hdCollection.Contains("yonghuh") ? hdCollection.Get("yonghuh").ToString() : ""; }
            set { hdCollection.Set("yonghuh", value); }
        }

        /// <summary>
        ///     当前文本框中的用户号
        /// </summary>
        public string YONGHUHINPUT
        {
            get { return txtYongHuH.Text; }
            set { txtYongHuH.Text = value; }
        }

        /// <summary>
        /// 获取当前文本框中用户号是否与查询出的用户号一致(此种情况应用于用户查询用户信息后又修改了用户号)
        /// </summary>
        public bool YONGHUHMATCH
        {
            get { return this.YONGHUH == YONGHUHINPUT; }
        }

        /// <summary>
        /// 标识当前查询过的用户号是否存在
        /// </summary>
        public bool YONGHUHEXISTS
        {
            get { return this.YONGHUH != ""; }
        }


        /// <summary>
        ///     来函编号
        /// </summary>
        public string LAIHANBH
        {
            set { txtLaiHanBH.Text = value; }
            get { return txtLaiHanBH.Text; }
        }

        /// <summary>
        ///     站点
        /// </summary>
        public string ZHANDIANBH
        {
            get { return Convert.ToString(ViewState["ZHANDIANBH"]); }
            set { ViewState["ZHANDIANBH"] = value; }
        }

        /// <summary>
        ///     管理块号
        /// </summary>
        public string GUANLIKBH
        {
            get { return Convert.ToString(ViewState["GUANLIKBH"]); }
            set { ViewState["GUANLIKBH"] = value; }
        }

        /// <summary>
        ///     判断引用页面类别   1月调整登记  2月调整修改  3其他页面调用 不可修改
        /// </summary>
        public int ControlType
        {
            get { return Convert.ToInt32(ViewState["ControlType"]); }
            set { ViewState["ControlType"] = value; }
        }

        #endregion

        #region 变量

        #endregion

        #region 事件

        /// <summary>
        ///     加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
                SetDisplay();
            }
        }


        /// <summary>
        ///     响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, CallbackEventArgs e)
        {
            DataRowCollection drc = null;
            if ((int) LaiHanLX < 20)
                drc = new YS_YG_YONGHUXXBLL().SelectYS_YG_YONGHUXXesDynamic(
                    "I_JLZT=0 AND I_LEIXING=1 AND " +
                    ((BusinessTool.ZHANDIANBH() == "00" || BusinessTool.ZHANDIANBH() == "51") ? "1=1"
                    : "S_ZHANDIANBH=" + BusinessTool.ZHANDIANBH()) + "and S_YONGHUH='" + txtYongHuH.Text + "'", null).Rows;
            else
                drc = new QS_YG_YONGHUXXBLL()
                    .SelectQS_YG_YONGHUXXesDynamic(
                        "I_JLZT=0 AND S_YONGHUH='" + txtYongHuH.Text + "' AND I_WTYPE=" + BusinessTool.WType, null)
                    .Rows;
            if (drc.Count == 0)
            {
                e.Result = e.Parameter + "|-1|您输入的用户号有误,请重新输入！";
            }
            else
            {
                if ((int) LaiHanLX <= 20)
                {
                    var ucinfo = Page.FindControl("UCLHShenQingXX_BH") as UCLHShenQingXX_BH;
                    if (ucinfo.ExistsYongHu(txtYongHuH.Text))
                        e.Result = e.Parameter + "|-1|列表中已添加该用户。";
                    else
                        e.Result = e.Parameter + "|0|OK";
                }
                else
                {
                    e.Result = e.Parameter + "|0|OK";
                }
            }
        }

        /// <summary>
        ///     前台验证后实际执行后台操作
        /// </summary>
        protected void btnActPerform_Click(object sender, EventArgs e)
        {
            if ((int) LaiHanLX < 20)
            {
                var ucinfo = Page.FindControl("UCLHShenQingXX_BH") as UCLHShenQingXX_BH;
                ucinfo.AddYongHu(txtYongHuH.Text);
            }
            else
            {
                var ucinfo = Page.FindControl("UCLHShenQingXX_BHQS") as UCLHShenQingXX_BHQS;
                ucinfo.AddYongHu(txtYongHuH.Text);
            }
            this.txtYongHuH.Focus();
        }

        #endregion

        #region 方法

        /// <summary>
        ///     配置控件
        /// </summary>
        public void InitControl()
        {
        }

        private void SetDisplay()
        {
            if (LaiHanLC == eLaiHanLCBH.未登记)
            {
                txtLaiHanBH.Visible = true;
                txtYongHuH.Visible = true;
                txtYongHuH.ClientEnabled = true;
                //this.btnAdd.Visible = true;
                lblYongHuH.Visible = true;
                txtYongHuH.Focus();
            }
            else if (LaiHanLC == eLaiHanLCBH.预登记)
            {
                txtLaiHanBH.Visible = true;
                txtYongHuH.Visible = true;
                //PageTools.SetDisabled(this.txtYongHuH,true);
                txtYongHuH.ClientEnabled = false;
                //this.btnAdd.Visible = false;
                lblYongHuH.Visible = true;
            }
            else
            {
                txtLaiHanBH.Visible = true;
                txtYongHuH.Visible = false;
                //this.btnAdd.Visible = false;
                lblYongHuH.Visible = false;
            }
        }

        /// <summary>
        ///     验证数据
        /// </summary>
        public ValidateRS Validate()
        {
            var rs = new ValidateRS();

            rs.IsSuccess = true;
            return rs;
        }

        /// <summary>
        ///     清除数据
        /// </summary>
        public void ClearInfo()
        {
            txtLaiHanBH.Text = "";
            txtYongHuH.Text = "";
            YONGHUH = "";
        }

        /// <summary>
        ///     根据来函加载信息
        /// </summary>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            if (laihanxx.ID == 0)
                LaiHanLC = eLaiHanLCBH.未登记;
            else
                LaiHanLC = (eLaiHanLCBH) Enum.Parse(typeof(eLaiHanLCBH), laihanxx.I_LIUCHENGBH.ToString());
            SetDisplay();
            //加载许可号等信息
            LAIHANBH = laihanxx.S_LAIHANBH;
            if ((int) LaiHanLX < 20)
            {
                ZHANDIANBH = laihanxx.S_ZHANDIANBH;
                GUANLIKBH = laihanxx.S_GUANLIKBH;
            }

            YONGHUH = laihanxx.S_YONGHUBH;
            txtLaiHanBH.Text = laihanxx.S_LAIHANBH;
        }

        /// <summary>
        ///     获取来函用户信息
        /// </summary>
        /// <param name="laihan"></param>
        /// <returns></returns>
        public YS_LH_YONGHUXX GetLHYONGHUXX(YS_LH_LAIHANXX laihan)
        {
            return null;
        }

        #endregion
    }
}